<template>
    <div>系统登录中...</div>
</template>
<script>
export default {
  name: "Auth",
  mounted() {
    var token = this.$route.query["token"];
    if(token == null || token == undefined)
        return;

    // sign-out, first
    localStorage.clear();

    this.$user.setToken(token);
    this.$user.getUserInformation().then(result => {
      var data = result.data;
      console.log(data);

      if (data.success) {
        var user = data.data;

        //store.state["user"] = user;
        //store.state['isAuthenticated'] = true;
        const token = data.data.access_token;
        //this.$user.setToken(token);

        //Set cookies.
        //console.log('user-info: ', user);
        //this.$cookies['user_id'] = user.user_id;
        //this.$cookies["token"] = token;
        localStorage.setItem("token", token);
        localStorage.setItem("user", JSON.stringify(user));

        var path = "/";
        this.$router.replace({ path: path });
      } else {
        alert(data.data.message);
      }
    });
  }
};
</script>